using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

namespace Code5Systems.FormMaster.Business
{
	
#region Class FormControlInfo
	
	[Serializable()]
	[XmlRoot("Control")]
	public class FormControlInfo
	{
		
#region Private Members
		
		private List<FormControlInfo> _validators;
		private List<FMListItem> _listItems;
		
#endregion
		
#region Constructors
		public FormControlInfo()
		{
			Text = string.Empty;
			Label = string.Empty;
			LabelCssClass = "SubHead";
			Type = ControlType.TextBox;
			TextMode = TextBoxMode.SingleLine;
			Width = string.Empty;
			Height = string.Empty;
			Columns = string.Empty;
			Rows = string.Empty;
			Required = false;
			Hidden = false;
			MaxLength = string.Empty;
			ErrorMessage = string.Empty;
			ControlToValidate = string.Empty;
			CssClass = "NormalTextBox";
			Display = ValidatorDisplay.Dynamic;
			ValidationExpression = string.Empty;
			@Checked = false;
			TableRow = "1";
			TableCol = "1";
			Position = "1";
			InitialValue = string.Empty;
			RepeatColumns = "1";
			RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Vertical;
			SelectionMode = ListSelectionMode.Multiple;
			Operator = ValidationCompareOperator.DataTypeCheck;
			ValDataType = ValidationDataType.String;
			ControlToCompare = string.Empty;
			ValueToCompare = string.Empty;
			Enabled = true;
			ColSpan = "1";
			RowSpan = "1";
			AutoFillField = false;
			AutoFillType = FormController.AutoFillType.None;
			AutoFillFrom = string.Empty;
			HideLabel = false;
			MaxFileSize = 1000;
			StoreInDB = false;
			FileTypes = string.Empty;
			TabIndex = "1";
			LabelAlign = HorizontalAlign.NotSet;
			ControlAlign = HorizontalAlign.NotSet;
			ButtonType = Code5Systems.FormMaster.Business.ButtonType.LinkButton;
			ButtonImage = string.Empty;
			ListItemToSave = FormController.ListItemToSave.Text;
			SendValueBy = FormController.SendValueBy.None;
			HideFileExtensions = false;
			HideMaxSize = false;
			FillListItemText = string.Empty;
			FillListItemValue = string.Empty;
			ConnectionString = string.Empty;
			FieldQuery = string.Empty;
			AttachFile = false;
			ARToken = string.Empty;
			ExcludeLink = false;
			ExcludeField = false;
			WrapHard = false;
			UseCalendar = false;
			EncryptField = false;
			MinChecked = 1;
			MaxChecked = 0;
			FieldName = string.Empty;
			AllowMarkup = false;
			ShowOnOwnRow = false;
			Formula = String.Empty;
			Placeholder = String.Empty;
		}
#endregion
		
#region Implicit Public Properties
		
		[XmlAttribute("ID")]
		public string ID {get; set;}
		
		[XmlElement("Text")]
		public string Text {get; set;}
		
		[XmlElement("Label")]
		public string Label {get; set;}
		
		[XmlAttribute("LabelCssClass")]
		public string LabelCssClass {get; set;}
		
		[XmlAttribute("Type")]
		public ControlType Type {get; set;}
		
		[XmlAttribute("TextMode")]
		public TextBoxMode TextMode {get; set;}
		
		[XmlAttribute("Width")]
		public string Width {get; set;}
		
		[XmlAttribute("Height")]
		public string Height {get; set;}
		
		[XmlAttribute("Columns")]
		public string Columns {get; set;}
		
		[XmlAttribute("Rows")]
		public string Rows {get; set;}
		
		[XmlAttribute("Required")]
		public bool Required {get; set;}
		
		[XmlAttribute("Hidden")]
		public bool Hidden {get; set;}
		
		[XmlAttribute("MaxLength")]
		public string MaxLength {get; set;}
		
		[XmlAttribute("ErrorMessage")]
		public string ErrorMessage {get; set;}
		
		[XmlAttribute("ControlToValidate")]
		public string ControlToValidate {get; set;}
		
		[XmlAttribute("CssClass")]
		public string CssClass {get; set;}
		
		[XmlAttribute("Display")]
		public ValidatorDisplay Display {get; set;}
		
		[XmlAttribute("ValidationExpression")]
		public string ValidationExpression {get; set;}
		
		[XmlAttribute("Checked")]
		public bool Checked {get; set;}
		
		[XmlAttribute("TableRow")]
		public string TableRow {get; set;}
		
		[XmlAttribute("TableCol")]
		public string TableCol {get; set;}
		
		[XmlAttribute("Position")]
		public string Position {get; set;}
		
		[XmlAttribute("InitialValue")]
		public string InitialValue {get; set;}
		
		[XmlAttribute("RepeatColumns")]
		public string RepeatColumns {get; set;}
		
		[XmlAttribute("RepeatDirection")]
		public System.Web.UI.WebControls.RepeatDirection RepeatDirection {get; set;}
		
		[XmlAttribute("SelectionMode")]
		public ListSelectionMode SelectionMode {get; set;}
		
		[XmlAttribute("Operator")]
		public ValidationCompareOperator Operator {get; set;}
		
		[XmlAttribute("ValDataType")]
		public ValidationDataType ValDataType {get; set;}
		
		[XmlAttribute("ControlToCompare")]
		public string ControlToCompare {get; set;}
		
		[XmlAttribute("ValueToCompare")]
		public string ValueToCompare {get; set;}
		
		[XmlAttribute("Enabled")]
		public bool Enabled {get; set;}
		
		[XmlAttribute("ColSpan")]
		public string ColSpan {get; set;}
		
		[XmlAttribute("RowSpan")]
		public string RowSpan {get; set;}
		
		[XmlAttribute("AutoFillField")]
		public bool AutoFillField {get; set;}
		
		[XmlAttribute("AutoFillFrom")]
		public string AutoFillFrom {get; set;}
		
		[XmlAttribute("AutoFillType")]
		public FormController.AutoFillType AutoFillType {get; set;}
		
		[XmlAttribute("HideLabel")]
		public bool HideLabel {get; set;}
		
		[XmlAttribute("MaxFileSize")]
		public int MaxFileSize {get; set;}
		
		[XmlAttribute("StoreInDB")]
		public bool StoreInDB {get; set;}
		
		[XmlAttribute("FileTypes")]
		public string FileTypes {get; set;}
		
		[XmlAttribute("TabIndex")]
		public string TabIndex {get; set;}
		
		[XmlAttribute("LabelAlign")]
		public HorizontalAlign LabelAlign {get; set;}
		
		[XmlAttribute("ControlAlign")]
		public HorizontalAlign ControlAlign {get; set;}
		
		[XmlAttribute("ButtonType")]
		public Code5Systems.FormMaster.Business.ButtonType ButtonType {get; set;}
		
		[XmlAttribute("ButtonImage")]
		public string ButtonImage {get; set;}
		
		[XmlAttribute("ListItemToSave")]
		public FormController.ListItemToSave ListItemToSave {get; set;}
		
		[XmlAttribute("SendValueBy")]
		public FormController.SendValueBy SendValueBy {get; set;}
		
		[XmlAttribute("SendValueByName")]
		public string SendValueByName {get; set;}
		
		[XmlAttribute("CookieExpires")]
		public int CookieExpires {get; set;}
		
		[XmlAttribute("HideFileExtensions")]
		public bool HideFileExtensions {get; set;}

		[XmlAttribute("HideMaxSize")]
		public bool HideMaxSize { get; set; }
		
		[XmlAttribute("FillListItemText")]
		public string FillListItemText {get; set;}
		
		[XmlAttribute("FillListItemValue")]
		public string FillListItemValue {get; set;}
		
		[XmlElement("ConnectionString")]
		public string ConnectionString {get; set;}
		
		[XmlElement("FieldQuery")]
		public string FieldQuery {get; set;}
		
		[XmlElement("CascadingFieldQuery")]
		public string CascadingFieldQuery {get; set;}
		
		[XmlAttribute("AttachFile")]
		public bool AttachFile {get; set;}
		
		[XmlAttribute("ARToken")]
		public string ARToken {get; set;}
		
		[XmlAttribute("ExcludeLink")]
		public bool ExcludeLink {get; set;}
		
		[XmlAttribute("ExcludeField")]
		public bool ExcludeField {get; set;}
		
		[XmlAttribute("WrapHard")]
		public bool WrapHard {get; set;}
		
		[XmlAttribute("UseCalendar")]
		public bool UseCalendar {get; set;}
		
		[XmlAttribute("EncryptField")]
		public bool EncryptField {get; set;}
		
		[XmlAttribute("MinChecked")]
		public int MinChecked {get; set;}
		
		[XmlAttribute("MaxChecked")]
		public int MaxChecked {get; set;}
		
		[XmlAttribute("FieldName")]
		public string FieldName {get; set;}
		
		[XmlAttribute("AllowMarkup")]
		public bool AllowMarkup {get; set;}
		
		[XmlAttribute("IsParentList")]
		public bool IsParentList {get; set;}
		
		[XmlAttribute("CascadingList")]
		public bool CascadingList {get; set;}
		
		[XmlAttribute("PromptText")]
		public string PromptText {get; set;}
		
		[XmlAttribute("NotFoundText")]
		public string NotFoundText {get; set;}
		
		[XmlAttribute("ParentControlID")]
		public string ParentControlID {get; set;}
		
		[XmlAttribute("ChildControlName")]
		public string ChildControlName {get; set;}
		
		[XmlAttribute("IsChildList")]
		public bool IsChildList {get; set;}
		
		[XmlAttribute("ChildControlID")]
		public string ChildControlID {get; set;}
		
		[XmlAttribute("SelectText")]
		public string SelectText {get; set;}
		
		[XmlAttribute("SetFocusOnError")]
		public bool SetFocusOnError {get; set;}

		[XmlAttribute("ShowOnOwnRow")]
		public bool ShowOnOwnRow { get; set; }

		[XmlElement("Formula")]
		public string Formula { get; set; }

		[XmlAttribute("Page")]
		public int Page { get; set; }

		[XmlIgnore]
		public string CalcId
		{
			get
			{
				int col;
				if (int.TryParse(this.TableCol, out col))
				{
					col += 64;
				}
				return String.Format("{0}{1}{2}", (char)col, this.Page, this.TableRow);
			}
		}

		[XmlElement("Placeholder")]
		public string Placeholder { get; set; }
		
#endregion
		
#region Explicit Public Properties
		
		[XmlArray("Validators")][XmlArrayItem("Control", Type = typeof(FormControlInfo))]public List<FormControlInfo> Validators
		{
			get
			{
				if (_validators == null)
				{
					_validators = new List<FormControlInfo>();
				}
				
				return _validators;
				
			}
		}
		
		[XmlArray("ListItems")][XmlArrayItem("ListItem", Type = typeof(FMListItem))]public List<FMListItem> ListItems
		{
			get
			{
				if (_listItems == null)
				{
					_listItems = new List<FMListItem>();
				}
				
				return _listItems;
			}
		}
		
#endregion
		
#region Public Methods
		
		
		public bool IsEqualTo(FormControlInfo objFormControlInfo)
		{
			bool bIsEqual = false;
			
			if (objFormControlInfo != null)
			{
				if (this.TableCol == objFormControlInfo.TableCol)
				{
					if (this.TableRow == objFormControlInfo.TableRow)
					{
						bIsEqual = true;
					}
				}
			}
			
			return bIsEqual;
			
		}
		
#endregion
	}
	
#endregion
	
}
